var menus = [{
	"name": "系统管理",
	"icon": "&#xe6b8;",
	"route": "",
	"children": [{
		"name": "账号管理",
		"route": "member",
		"children": false
	}, {
		"name": "申请人认证审核",
		"route": "applicantVerify",
		"children": false
	},{
		"name": "机构申请认证审核",
		"route": "organVerify",
		"children": false
	},{
		"name": "院士专家申请认证审核",
		"route": "acadVerify",
		"children": false
	}, {
		"name": "申请人申报审核",
		"route": "applicantApply",
		"children": false
	}]
}, {
	"name": "项目信息",
	"icon": "&#xe724;",
	"route": "",
	"children": [{
		"name": "项目列表",
		"route": "allProject",
		"children": false
	},{
        "name": "人才列表",
        "route": "allApplicant",
        "children": false
    }]
}];

// 构建左侧菜单栏
layui.use(['jquery'], function() {
	var $ = jQuery = layui.$;

	var menuHtml = "";
	menus.forEach(function(data) {
		menuHtml += isHaveChildren(data);
	});
	$("#nav").html(menuHtml);

	// 获取后台数据
	// 	AJAX.query("http://testdpmpapi.dmall.com/project/overviewCount", "", function(res) {
	// 		console.log(res)
	// 	});
});

// 判断是否存在子集
function isHaveChildren(data) {
	var html = '';
	var icon = isHaveIcon(data);
	if (data.children && data.children.length) { // 存在子集
		var childrenHtml = getChildrenHtml(data.children);
		html += '<li name="' + data.name + '" route="' + data.route + '">';
		html += '<a href="javascript:;">';
		html += '<i class="iconfont" lay-tips="' + data.name + '">' + icon + '</i>';
		html += '<cite>' + data.name + '</cite>';
		html += '<i class="iconfont nav_right">&#xe697;</i>';
		html += '</a>';
		html += childrenHtml;
		html += '</li>';
	} else { // 不存在子集
		html += '<li name="' + data.name + '" route="' + data.route + '">';
		html += '<a>';
		html += '<i class="iconfont" lay-tips="' + data.name + '">' + icon + '</i>';
		html += '<cite>' + data.name + '</cite>';
		html += '</a>';
		html += '</li>';
	}

	return html;
}

// 获取子集内容
function getChildrenHtml(data) {
	var html = '<ul class="sub-menu">';
	data.forEach(function(info) {
		html += isHaveChildren(info); // 判断是否存在子集
	});
	html += '</ul>';

	return html;
}

// 判断是否有Icon
function isHaveIcon(data) {
	var icon = "";
	if (data.icon) {
		icon = data.icon;
	} else {
		icon = "&#xe6a7;";
	}
	return icon;
}
